package com.sinaapp.gavinzhang.GSpider.management;

import java.io.Serializable;
import java.util.UUID;

/**
 * @author gavin
 * @version 1.0
 * @date 2016/3/19
 * @description 注册存根
 */
public class Stub implements Serializable{
    private static final long serialVersionUID = 4077329331699640332L;

    public final static String nameNone = "None";
    private String name;
    private long useCount;
    private boolean usable;
    private String token;


    private final static Stub noneStub = new Stub();
    public static Stub getNoneStub(){
        return noneStub;
    }
    public static Stub newStub(){
        Stub stub = new Stub();
        stub.setToken(UUID.randomUUID().toString());
        stub.setUseCount(0);
        stub.setUsable(true);
        return stub;
    }

    public Stub() {
        this(nameNone,Long.MAX_VALUE,false,nameNone);
    }

    public Stub(String name, long useCount, boolean usable, String token) {
        this.name = name;
        this.useCount = useCount;
        this.usable = usable;
        this.token = token;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getUseCount() {
        return useCount;
    }

    public void setUseCount(long useCount) {
        this.useCount = useCount;
    }

    public boolean isUsable() {
        return usable;
    }

    public void setUsable(boolean usable) {
        this.usable = usable;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Stub stub = (Stub) o;

        return getToken().equals(stub.getToken());

    }

    @Override
    public int hashCode() {
        return getToken().hashCode();
    }

    @Override
    public String toString() {
        return "Stub{" +
                "name='" + name + '\'' +
                ", useCount=" + useCount +
                ", usable=" + usable +
                ", token='" + token + '\'' +
                '}';
    }
}
